<template>
	<view class="c-group-item" @click="emitClick" :style="{'padding-left':imgShow?'32rpx':'20rpx'}">
		<view class="c-g-i-img" v-if="imgShow">
			<u-icon :name="icon" :custom-style="iconStyle" v-if="icon&&!imgSrc"></u-icon>
			<image :src="imgSrc" mode="widthFix" v-else></image>
		</view>
		<view class="c-g-i-content">
			<view class="content-title" v-if="title">{{title}}</view>
			<slot name="title" v-else></slot>
			<view class="content-value">
				<view class="value" v-if="value">{{value}}</view>
				<slot name="value" v-else></slot>
				<u-icon v-if="arrow" name="arrow-right" :style="[arrowStyle]" class="arrow"></u-icon>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		props: {
			imgSrc: {
				type: String,
				default: ''
			},
			imgShow: {
				type: Boolean,
				default: true
			},
			arrow: {
				type: Boolean,
				default: true
			},
			title: {
				type: [String, Number],
				default: ''
			},
			value: {
				type: [String, Number],
				default: ''
			},
			icon: {
				type: String,
				default: ''
			},
			arrowDirection: {
				type: String,
				default: 'right'
			},
			iconStyle: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {

			}
		},
		computed: {
			arrowStyle() {
				let style = {};
				if (this.arrowDirection == 'up') style.transform = 'rotate(-90deg)';
				else if (this.arrowDirection == 'down') style.transform = 'rotate(90deg)';
				else style.transform = 'rotate(0deg)';
				return style;
			}
		},
		methods: {
			emitClick() {
				this.$emit('click')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.c-group-item {
		width: 100%;
		display: flex;
		background-color: #fff;
		align-items: center;

		&:active {
			background-color: #ccc;
		}
		&:active .c-g-i-content{
			border-bottom: 2rpx solid #ccc;
		}

		.c-g-i-img {
			width: 70rpx;
			font-size: 38rpx;
			text-align: center;
			position: relative;

			image {
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				width: 50rpx;
			}
		}

		.c-g-i-content {
			margin-left: 20rpx;
			padding-right: 30rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 2rpx solid #f3f3f3;

			.content-title {
				color: #000;
				font-weight: 500;
			}

			.content-value {
				display: flex;
				align-items: center;
				padding: 30rpx 0;

				.value {
					color: #666;
				}

				.arrow {
					color: #ddd;
					margin-left: 15rpx;
				}
			}

		}
	}
</style>
